package com.hx.myapp.jump;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.hx.myapp.R;

import util.ToastUtil;

public class AActivity extends AppCompatActivity {
   private Button mBtnJump,mBtnJump2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aactivity);
        mBtnJump = findViewById(R.id.btn_JumpA);
        mBtnJump2 = findViewById(R.id.btn_Jump_2);
        Log.d("AActivity","----onCreate----");
        Log.d("AActivity","taskid:" + getTaskId()+",hash:" + hashCode());
        logtaskName();
        mBtnJump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //显式跳转1
               Intent intent = new Intent(AActivity.this,BActivity.class);
               Bundle bundle = new Bundle();
               bundle.putString("name","天哥");
               bundle.putInt("number",88);
               intent.putExtras(bundle);
              // startActivity(intent);
               startActivity(intent);

                //显式2
               // Intent intent = new Intent();
               // intent.setClass(AActivity.this,BActivity.class);
               // startActivity(intent);
                //显式3
                //Intent intent = new Intent();
                //intent.setClassName(AActivity.this,"com.hx.myapp.jump.BActivity");
               // startActivity(intent);
                //显式4
               // Intent intent = new Intent();
               // intent.setComponent(new ComponentName(AActivity.this,"com.hx.myapp.jump.BActivity"));
               // startActivity(intent);
                //隐式调用
              //  Intent intent = new Intent();
              //  intent.setAction("com.hx.myapp.test.BActivity");
              //  startActivity(intent);
            }

        });
        mBtnJump2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AActivity.this,AActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        ToastUtil.showMag(AActivity.this,data.getExtras().getString("title"));
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("AActivity","----onNewIntent----");
        Log.d("AActivity","taskid:" + getTaskId()+",hash:" + hashCode());
        logtaskName();
    }

    private void logtaskName(){
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.d("AActivity",info.taskAffinity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        };
    }
}